package com.TempletGenerate;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/11/29/21:42
 * @Description:
 * @Target:
 */
public class 日期转换器 {
    public static void main(String[] args) {
        GetDaysByYYMMDD("2014 年1月1日");
        GetDaysByYYMMDD("2001/03/12");
        GetDaysByYYMMDD("20011102");


    }




    // 我先编一个,日期进来就变成天数
    // 进来的字符串
    public static int GetDaysByYYMMDD(String ss){
        int sum = 0;
        int year = 0;
        int month = 0;
        int day = 0;
        int count = 0;
        int index = 0;
        // 进来先解析字符串
        for (int i = 0; i <= ss.length()-1; i++) {
            if (count<4&&ss.charAt(i) >= '0' && ss.charAt(i) <= '9') {
                year += (ss.charAt(i)-'0')*Math.pow(10,(3-count));
                count++;
            }else if (count >= 4){
                count=0;
                index = i;
                break;
            }
        }

        for (int i = index; i <= ss.length()-1; i++) {
            if (count<2) {
                if (ss.charAt(i) >= '0' && ss.charAt(i) <= '9'){
                    month += (ss.charAt(i)-'0')*Math.pow(10,(1-count));
                    count++;
                }else if (count == 1&&(!(ss.charAt(i) >= '0' && ss.charAt(i) <= '9'))){
                    month = month/10;
                    count=3;
                }

            }else if (count >= 2){
                count=0;
                index = i;
                break;
            }
        }

        for (int i = index; i <= ss.length()-1; i++) {
            if (count<2) {
                if (ss.charAt(i) >= '0' && ss.charAt(i) <= '9'){
                    day += (ss.charAt(i)-'0')*Math.pow(10,(1-count));
                    count++;
                }else if (count == 1&&(!(ss.charAt(i) >= '0' && ss.charAt(i) <= '9'))){
                    day = day/10;
                    count=3;
                }else if (count >= 2){
                    count=0;
                    break;
                }

            }
        }

        if (count==1){
            day = day/10;
        }


        System.out.println(year+":"+month+":"+day);


        return sum;
    }
}
